package com.soft.line.controller;

import com.soft.line.entity.*;
import com.soft.line.service.ButtonInfoService;
import com.soft.line.service.CodeDetailService;
import com.soft.line.service.MenuInfoService;
import com.soft.line.service.RoleInfoService;
import com.soft.line.util.exception.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api( description = "通用接口")
@Slf4j
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private CodeDetailService codeDetailService;
    @Autowired
    private ButtonInfoService buttonInfoService;
    @Autowired
    private MenuInfoService menuInfoService;
    @Autowired
    private RoleInfoService roleInfoService;

    @ApiOperation(value = "获取枚举值lasCodeItem")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemTypeId", value = "itemTypeId", required = true, dataType = "String", paramType = "path")
    })
    @GetMapping("lasCodeItem/{itemTypeId}")
    public CommonResult<List<LasCodeItem>> getCodeDetailByCodeType(@PathVariable("itemTypeId") String itemTypeId) {
        return CommonResult.success(codeDetailService.selectByCodeType(itemTypeId));
    }

    @GetMapping("/buttons")
    @ApiOperation(value = "获取所有按钮列表")
    public CommonResult<List<ButtonInfo>> getAllButtons() {
        return CommonResult.success(buttonInfoService.selectAll());
    }

    @GetMapping("/topMenu")
    @ApiOperation(value = "获取所有顶级菜单")
    public CommonResult<List<MenuInfo>> getTopMenu() {
        return CommonResult.success(menuInfoService.selectTopMenu());
    }

    @GetMapping("/pageMenu")
    @ApiOperation(value = "获取所有有操作按钮的页面")
    public CommonResult<List<MenuInfo>> getAllButtonMenu() {
        return CommonResult.success(menuInfoService.selectSonMenus());
    }

    @GetMapping("/roleNames")
    @ApiOperation(value = "获取所有角色名")
    public CommonResult<List<RoleInfo>> getAllRoleInfo() {
        return CommonResult.success(roleInfoService.selectAll());
    }


    @GetMapping("getDepByRole")
    @ApiOperation(value = "根据角色获取部门")
    public CommonResult<List<LasDepartmentInfo>> getDepByRole() {
        return CommonResult.success(codeDetailService.getDepByRole());
    }

    @GetMapping("/deparments")
    @ApiOperation(value = "获取所有部门列表")
    public CommonResult<List<LasDepartmentInfo>> getAllDep() {
        return CommonResult.success(codeDetailService.selectAllDep());
    }

}
